<template>
  <div>
    <div class="login_box" :style="bg">
      <div class="mid--1150 pos_rel">
        <div class="login_body rf pos_abs">
          <div class="title flex">
            <div class="logo">
              <img />
            </div>
            <span class="name">修改密码</span>
          </div>
          <hr />
          <br />

          <div class="main">
            <div class="text">
              <input
                type="password"
                class="innerBox"
                v-model="upwd"
                placeholder="请输入新密码"
                name="upwd"
                required
                autofocus
              />
              <div class="mt--15"></div>
            </div>&nbsp;
            <br />

            <div class="text">
              <input
                type="password"
                class="innerBox"
                v-model="check_upwd"
                placeholder="确认新密码"
                name="new_upwd"
                required
                autofocus
              />
              <div class="mt--15"></div>
            </div>&nbsp;
            <br />

            <input
              class="button_login"
              type="button"
              value="修改"
              id="bt-register"
              @click="update_upwd()"
            />
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
var _self;
import "@/assets/css/frx/common.css";
import "@/assets/css/frx/font-awesome-4.7.0/css/font-awesome.min.css";
import "@/assets/css/frx/login.css";
import my_can from "@/api/frx/js/my_can";
import pub from "../../api/frx/js/public";
export default {
  data() {
    return {
      upwd: "",
      check_upwd: "",
      uid: "",
      bg: {
        backgroundImage: "url(" + require("@/assets/imgs/cl/img1.jpg"),
        backgroundRepeat: "no-repeat",
        backgroundPosition: "center center ",
        backgroundSize: "100%"
      }
    };
  },
  methods: {
    async update_upwd() {
      try {
        pub.ch_upwd(_self.upwd);
        pub.ch_check_upwd(_self.upwd, _self.check_upwd);

        var gg = await pub.http_post("user", "password/forget", {
          newPassword: _self.check_upwd,
          uid: _self.uid
        });
        console.log(gg);

        if (gg.result == "failed") {
          alert("修改失败!");
          _self.$router.push("retrievePwd");
        } else {
          alert("修改成功，请重新登录!");
          sessionStorage.removeItem("userInfo");
          _self.$router.push("login");
        }
      } catch (e) {
        switch (e.message) {
          case "upwd":
            alert("请输入正确的6-16位密码");

            break;

          case "check_upwd":
            alert("密码不一致");

            break;
        }
      }
    }
  },

  created() {
    // 路由传参(可见)
    _self = this;
    _self.uid = _self.$route.params.uid;
  }
};
</script>

<style scoped>
</style>